<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="" lay-filter="form-filter">
			<div class="mainBox">
				<div class="main-container">
				    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label required">ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="id" class="layui-input" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" required lay-verify="required" placeholder="" autocomplete="new-password" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">编码</label>
                        <div class="layui-input-block">
                            <input type="text" name="code" required lay-verify="required" placeholder="" autocomplete="new-password" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">值</label>
                        <div class="layui-input-block">
                            <input type="text" name="val" required lay-verify="required" placeholder="" autocomplete="new-password" class="layui-input">
                        </div>
                    </div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
						</div>
					</div>
				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="submit-filter">
						<i class="layui-icon layui-icon-ok"></i>提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>重置
					</button>
				</div>
			</div>
		</form>
		<script src="../../../component/layui/layui.js"></script>
		<script src="../../../component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				let url = layui.url();
				let id = url.search.id;

				form.on('submit(submit-filter)', function(data) {
				    if(id) {
				        $.put('/vtl-config', data.field, function(result) {
                            if (result.code == 200) {
                                $.vtl.closeLayer();
                                parent.refresh();
                            }
                        });
				    } else {
				        $.post('/vtl-config', data.field, function(result) {
                            if (result.code == 200) {
                                $.vtl.closeLayer();
                                parent.refresh();
                            }
                        });
				    }

					return false;
				});

				window.init = function(id) {
				    if(id) {
                		$.get('/vtl-config/' + id, function(result) {
                            form.val("form-filter", result);
                        });
                    }
				}
				window.init(id);
			})
		</script>
	</body>
</html>
